home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / TURB_VIS / TVDMX / TVDMXHEX.PAS < prev    next >
Pascal/Delphi Source File  |  1994-06-20  |  5KB  |  197 lines

  1.  
  2. {■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■}
  3. {                            }
  4. {    tvDMXHEX  --Hexadecimal Data Editing Unit    }
  5. {    tvDMX      --data editing project (ver 2.x)    }
  6. {                            }
  7. {    Copyright (c) 1993  Randolph Beck        }
  8. {                P.O. Box  56-0487        }
  9. {                Orlando, FL 32856        }
  10. {                CIS:  72361,753        }
  11. {                            }
  12. {■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■}
  13.  
  14. Unit tvDMXHEX;
  15.  
  16. {$V-,X+,O+,D-,B-,R- }
  17.  
  18. interface
  19.  
  20. uses  Objects, Drivers, Views, Menus, App, RSet, DmxGizma, tvDMX, StdDMX;
  21.  
  22.  
  23. const
  24.     _HexLabels    =  '  0  1  2  3  4  5  6  7  8  9  A  B  C  D  E  F   0123456789ABCDEF ';
  25.  
  26.     HexInfo    =    ^A                    { show all zeroes }
  27.            + '\HH\HH\HH\HH\HH\HH\HH\HH'        { hex byte display }
  28.            + ^D + '-HH\HH\HH\HH\HH\HH\HH\HH'    {  of 16 bytes }
  29.            + '\ \'                { blank spaces }
  30.            + ^P + char(-16)            { position -16 bytes }
  31.            + 'c'^V#0#0'c'^V#0#0'c'^V#0#0'c'^V#0#0  { 16 characters }
  32.            + 'c'^V#0#0'c'^V#0#0'c'^V#0#0'c'^V#0#0  { Default Value }
  33.            + 'c'^V#0#0'c'^V#0#0'c'^V#0#0'c'^V#0#0  {      is ZERO. }
  34.            + 'c'^V#0#0'c'^V#0#0'c'^V#0#0'c'^V#0#0;
  35.  
  36.     HexLabels    :  string[length(_HexLabels)]  = _HexLabels;
  37.  
  38.  
  39. type
  40.     PDmxHexInd        = ^TDmxHexInd;
  41.     PDmxHex        = ^TDmxHex;
  42.     PDmxHexWin        = ^TDmxHexWin;
  43.  
  44.  
  45.       { hexadecimal record number indicator }
  46.     TDmxHexInd        =  OBJECT(TDmxRecInd)
  47.       procedure Draw;  VIRTUAL;
  48.     end;
  49.  
  50.  
  51.       { main tvDMX-editing view }
  52.     TDmxHex        =  OBJECT(TDmxEditor)
  53.       procedure EvaluateField;    VIRTUAL;
  54.       function    RecNumStr(RecNum : integer) : string;  VIRTUAL;
  55.     end;
  56.  
  57.  
  58.       { tvDMX-Window view }
  59.     TDmxHexWin        =  OBJECT(TDmxWindow)
  60.       constructor Init(var Bounds    : TRect;
  61.                 ATitle    : TTitleStr;
  62.                 ANumber   : integer;
  63.             var AData;
  64.                 BSize     : longint);
  65.       procedure InitDMX(ATemplate : string;  var AData;
  66.              ALabels, ARecInd : PDmxLink;
  67.              BSize     : longint);  VIRTUAL;
  68.       function    NewRecInd(Len : integer)  : PDmxLink;  VIRTUAL;
  69.     end;
  70.  
  71.  
  72. const
  73.     RDmxHexInd     :  TStreamRec =(
  74.     ObjType:   rnDmxHexInd;
  75.     VmtLink:   ofs(TypeOf(TDmxHexInd)^);
  76.     Load:       @TDmxHexInd.Load;
  77.     Store:       @TDmxHexInd.Store
  78.       );
  79.  
  80.  
  81.   procedure RegisterTVDMXHEX;
  82.  
  83.  
  84. implementation
  85.  
  86.  
  87.   { ══ TDmxHexInd ════════════════════════════════════════════════════════ }
  88.  
  89.  
  90. procedure TDmxHexInd.Draw;
  91. const bts  :  array[0..15] of char = '0123456789ABCDEF';
  92. var   A    :  string;
  93.       B    :  TDrawBuffer;
  94.       C    :  word;
  95. begin
  96.   C := GetColor(6);
  97.   MoveChar(B, ' ', C, Size.X);
  98.   With PDmxEditor(Link)^ do
  99.     A := '['
  100.     + bts[(CurrentRecord shr 12) and $0F]
  101.     + bts[(CurrentRecord shr  8) and $0F]
  102.     + bts[(CurrentRecord shr  4) and $0F]
  103.     + bts[CurrentRecord and $0F]
  104.     + bts[(CurrentField^.fieldnum + $0F) and $0F]
  105.     + ']';
  106.   While (length(A) > Size.X) and (A[2] = '0') do Delete(A,2,1);
  107.   If length(A) > Size.X then
  108.     MoveChar(B, showOVERFLOW, C, Size.X)
  109.    else
  110.     MoveStr(B[succ((Size.X) - length(A)) shr 1], A, C);
  111.   WriteBuf(0, 0, Size.X, 1, B);
  112. end;
  113.  
  114.  
  115.   { ══ TDmxHex ═══════════════════════════════════════════════════════════ }
  116.  
  117.  
  118. procedure TDmxHex.EvaluateField;
  119. { entire record must be redrawn if one byte is changed }
  120. begin
  121.   If FieldAltered then ReDrawRecord := TRUE;
  122.   TDmxEditor.EvaluateField;
  123. end;
  124.  
  125.  
  126. function  TDmxHex.RecNumStr(RecNum : integer) : string;
  127. const bts : array[0..15] of char = '0123456789ABCDEF';
  128. var   A   : string;
  129. begin
  130.   If (RecNum >= RecordLimit) then
  131.     A := '      '
  132.    else
  133.     begin
  134.     A := ' 0000 ';
  135.     If ((RecNum shr 12) and $0F > 0) then A[1] := bts[(RecNum shr 12) and $0F];
  136.     A[2] := bts[(RecNum shr  8) and $0F];
  137.     A[3] := bts[(RecNum shr  4) and $0F];
  138.     A[4] := bts[RecNum and $0F];
  139.     end;
  140.   RecNumStr := A;
  141. end;
  142.  
  143.  
  144.   { ══ TDmxHexWin ════════════════════════════════════════════════════════ }
  145.  
  146.  
  147. constructor TDmxHexWin.Init(var Bounds     : TRect;
  148.                  ATitle   : TTitleStr;
  149.                  ANumber  : integer;
  150.                  var AData;
  151.                  BSize      : longint);
  152. begin
  153.   TWindow.Init(Bounds, ATitle, ANumber);
  154.   InitDMX(HexInfo, AData, NewDmxLabels(HexLabels), NewRecInd(6), BSize);
  155.   Options := Options or ofTileable;
  156. end;
  157.  
  158.  
  159. procedure TDmxHexWin.InitDMX(ATemplate : string;  var AData;
  160.                   ALabels, ARecInd : PDmxLink; BSize : longint);
  161. var  R    : TRect;
  162. begin
  163.   GetExtent(R);
  164.   R.Grow(-1,-1);
  165.   Inc(R.A.Y, 2);
  166.  
  167.   Insert(New(PDmxHex, Init(ATemplate, AData, BSize, R,
  168.                   ALabels, ARecInd,
  169.                   StandardScrollBar(sbHorizontal+ sbHandleKeyboard),
  170.                   StandardScrollBar(sbVertical  + sbHandleKeyboard))));
  171. end;
  172.  
  173.  
  174. function  TDmxHexWin.NewRecInd(Len : integer)  : PDmxLink;
  175. begin
  176.   If Len <= 0 then
  177.     NewRecInd := nil
  178.    else
  179.     NewRecInd := New(PDmxHexInd, InitInsert(@Self, Len));
  180. end;
  181.  
  182.  
  183.   { ══════════════════════════════════════════════════════════════════════ }
  184.  
  185.  
  186. procedure RegisterTVDMXHEX;
  187. begin
  188.   RegisterType(RDmxHexInd);
  189. end;
  190.  
  191.  
  192.   { ══════════════════════════════════════════════════════════════════════ }
  193.  
  194.  
  195.  
  196. End.
  197.